#include "tower.h"

//4 Sekawan
Tower::Tower(string _name, string _url, int _type, int _att, int _range, int _cost, int _isbase, int _upgradable, int _posx, int _posy){
	name = _name;
	image_url = _url;
	type = _type;
	att = _att;
	range = _range;
	cost = _cost;
	isbase = _isbase;
	upgradable = _upgradable;
	posx = _posx;
	posy = _posy;
}

Tower::Tower(string _name, string _url, int _type, int _att, int _range, int _cost, int _isbase, int _upgradable){
	name = _name;
	image_url = _url;
	type = _type;
	att = _att;
	range = _range;
	cost = _cost;
	isbase = _isbase;
	upgradable = _upgradable;
	posx = -999;
	posy = -999;
}

Tower::~Tower(){

}

Tower::Tower(const Tower& T){
	name = T.name;
	image_url = T.image_url;
	type = T.type;
	att = T.att;
	range = T.range;
	cost = T.cost;
	isbase = T.isbase;
	upgradable = T.upgradable;
	posx = T.posx;
	posy = T.posy;
}

Tower& Tower::operator= (const Tower T){
	name = T.name;
	image_url = T.image_url;
	type = T.type;
	att = T.att;
	range = T.range;
	cost = T.cost;
	isbase = T.isbase;
	upgradable = T.upgradable;
	posx = T.posx;
	posy = T.posy;
	return *this;
}

//Getter Setter
string Tower::getName(){return name;}
string Tower::getURL(){return image_url;}
int Tower::getType(){return type;}
int Tower::getAtt(){return att;}
int Tower::getRange(){return range;}
int Tower::getCost(){return cost;}
int Tower::getIsBase(){return isbase;}
int Tower::getUpgradable(){return upgradable;}
int Tower::getPosX(){return posx;}
int Tower::getPosY(){return posy;}

void Tower::setName(string S){name = S;}
void Tower::setURL(string S){image_url = S;}
void Tower::setType(int n){type = n;}
void Tower::setAtt(int n){att = n;}
void Tower::setRange(int n){range = n;}
void Tower::setCost(int n){cost = n;}
void Tower::setIsBase(int n){isbase = n;}
void Tower::setUpgradable(int n){upgradable = n;}
void Tower::setPosX(int n){posx = n;}
void Tower::setPosY(int n){posy = n;}

bool Tower::canAttack(Enemy e){
	if((abs(e.getPosX() - posx)<=32*range)&&(abs(e.getPosY() - posy)<=32*range)){
		return true;
	}else{
		return false;
	}
}

void Tower::Attack(Enemy& e){
	if(e.getType()==1){
		if(type==1){
			e.getDamage(att);
		}else if(type==2){
			e.getDamage(att/2);
		}else{
			e.getDamage(att*2);
		}
	}else if(e.getType()==2){
		if(type==1){
			e.getDamage(att*2);
		}else if(type==2){
			e.getDamage(att);
		}else{
			e.getDamage(att/2);
		}
	}else if(e.getType()==3){
		if(type==1){
			e.getDamage(att/2);
		}else if(type==2){
			e.getDamage(att*2);
		}else{
			e.getDamage(att);
		}
	}
}

void Tower::DrawTower(sf::RenderWindow& window,sf::Sprite& s1)
{
	s1.SetPosition(posx,posy);
	window.Draw(s1);
}